import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-10-24
 * Time：09:24
 */

public class TestDemo {
    public static void main(String[] args) {
        String s = "leetcode";
        int[] arr = new int[26];
        for (int i = 0; i < s.length(); i++) {
            arr[s.charAt(i) - 97] += 1;
        }
        for (int i = 0; i < s.length(); i++) {
            if (arr[s.charAt(i) - 97] == 1) {
                System.out.print(s.charAt(i) + " ");
            }
        }
    }
    public static void main12(String[] args) {
        String str = "hello";
        //str = str + "world";实际上创建了三个对象
        StringBuilder strB = new StringBuilder();//1
        strB.append(str);
        strB.append("world");//2
        str = strB.toString();//3
        System.out.println(str);
    }
    /**
     * intern() 方法
     * @param args
     */
    public static void main11(String[] args) {
        char[] ch = new char[]{'a', 'b', 'c'};
        String str = new String(ch);
        //手动入池
        str.intern();
        String str2 = "abc";
        System.out.println(str == str2);
    }
    public static void main10(String[] args) {
        String s1 = "";
        String s2 = new String("");
        String s3 = "";
        System.out.println(s1==s2);
        System.out.println(s1==s3);
    }
    public static void main9(String[] args) {
        String s = "    wedasdasdas     ";
        System.out.println(s.trim());
        System.out.println(s);
    }
    public static void main8(String[] args) {
        String s = "asdsadnuidwdo";
        String s1 = s.substring(2);
        String s2 = s.substring(2,5);//[2,5)
        System.out.println(s1);
        System.out.println(s2);
    }
    public static void main7(String[] args) {
        String s = "10.160.21.66";
        String[] strings = s.split("\\.", 2);
        for (String string: strings) {
            System.out.println(string);
        }

        String s2 = "hello world&cs";
        String[] strings2 = s2.split(" |&");
        for (String string: strings2) {
            System.out.println(string);
        }

        String s3 = "ftp:\\10.160.21.66";
        String[] strings3 = s3.split("\\\\|\\.");
        for (String string: strings3) {
            System.out.println(string);
        }
    }
    /**
     * Java中对字符串本身的操作，都不是在原本的字符串上进行操作，因为字符串是不可变的
     */
    public static void main6(String[] args) {
        String s = "abababababcde";
        String s2 = s.replace('a', 'm');
        s2 = s.replace("ab", "cd");
        s2 = s.replaceAll("ab", "mp");
        s2 = s.replaceFirst("ab", "mp");
        System.out.println(s);
        System.out.println(s2);

    }
    public static void main5(String[] args) {
        String s = "hello";
        char[] chars = s.toCharArray();
        System.out.println(Arrays.toString(chars));

        String s1 = String.format("%d-%d-%d", 2023, 10, 24);
        System.out.println(s1);
    }
    /**
     * 大小写转换
     * @param args
     */
    public static void main4(String[] args) {
        String s = "hello";
        //返回一个新的对象
        String s2 = s.toUpperCase();
        System.out.println(s2);

        String s1 = "HelLo";
        String s3 = s1.toLowerCase();
        System.out.println(s3);
    }
    /**
     * int和String相互转换
     * valueOf用例
     * @param args
     */
    public static void main3(String[] args) {
        int a = 10;
        String s1 = String.valueOf(a);
        System.out.println(s1);

        String s2 = "1234";
        int ret = Integer.valueOf(s2);
        int ret2 = Integer.parseInt(s2, 8);
        System.out.println(ret);
        System.out.println(ret2);
    }

    /**
     * 查找字符、下标
     * charAt，indexOf，lastIndexOf
     * @param args
     */
    public static void main2(String[] args) {
        String s1 = "hello world";
        char ch1 = s1.charAt(2);
        System.out.println(ch1);
        //从前往后找
        int index1 = s1.indexOf('o');
        int index2 = s1.indexOf("lo");
        int index3 = s1.indexOf('o', 5);
        int index4 = s1.indexOf("ll", 5);
        //从后往前找
        int index5 = s1.lastIndexOf('o');
        System.out.println(index1+" "+index2+" "+index3+" "+index4+" "+index5);
    }

    /**
     * ==, equals, compareTo的差别
     * @param args
     */
    public static void main1(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("Hello");
        System.out.println(s1==s2);
        System.out.println(s1.equals(s2));
        System.out.println(s1.equalsIgnoreCase(s3));
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareTo(s3));
    }
}
